package com.google.gwt.livinglife.server.data;

import java.util.HashSet;
import java.util.Set;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.InheritanceStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import com.google.appengine.api.users.User;
import com.google.gwt.livinglife.client.data.BasicPostData;
import com.google.gwt.livinglife.client.data.BasicPostWithStatsData;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public abstract class BasicPostWithStats extends BasicPost {
	// We keep the number of elements in each set separately so that the entire set does not need to be fetched
	// when we just need the numbers.
	@Persistent
	private int num_liked = 0;
	
	@Persistent
	private int num_inspired = 0;
	
	@Persistent
	private int num_inappropriate = 0;
	
	@Persistent
	private Set<User> liked = new HashSet<User>();
	
	@Persistent
	private Set<User> inspired = new HashSet<User>();
	
	@Persistent
	private Set<User> found_inappropriate = new HashSet<User>();
	
	
	public BasicPostWithStats() {
		super();
	}

	public BasicPostWithStats(BasicPostWithStatsData data) {
		super((BasicPostData)(data));
	}


	public void like(User user) {
		liked.add(user);
		num_liked = liked.size();
	}
	
	public void inspired(User user) {
		inspired.add(user);
		num_inspired = inspired.size();
	}
	
	public void inappropriate(User user) {
		found_inappropriate.add(user);
		num_inappropriate = found_inappropriate.size();
	}
	
	public int getNum_liked() {
		return num_liked;
	}

	public int getNum_inspired() {
		return num_inspired;
	}

	public int getNum_inappropriate() {
		return num_inappropriate;
	}

	public Set<User> getLiked() {
		return liked;
	}

	public Set<User> getInspired() {
		return inspired;
	}

	public Set<User> getFound_inappropriate() {
		return found_inappropriate;
	}
}
